package FlyBirdGame;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Random;

public class Column {
    //图片
    BufferedImage image;
    //位置
    int x,y;
    //宽高
    int width,height;
    //柱子间缝隙
    int gap;
    //柱子间距离
    int distance;
    //随机数工具
    Random random = new Random();

    /**
     * 初始化第n个柱子
     */
    public Column(int n) throws  Exception{
    	String path = "img/bird_image/";
        image = ImageIO.read(new File(path,"column.png"));
        width = image.getWidth();
        height = image.getHeight();
        gap = 144;//固定鸟道----缝隙
        distance = 245;//固定柱间距
        x= 500+ (n-1) * distance;//第一根柱子和开始游戏处水平距离500----不能设置太近，否则开局就死
        y = random.nextInt(218)+132;//柱长最短132，最长350
    }

    //向左移动一步
    public void step(){
        x--;
        if(x==-width/2){
            x = distance * 2 - width/2;//------设置柱子刷新点，刚刚好
            y = random.nextInt(218) + 132;//继续伪随机柱子高度
        }
    }
}
